package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.UserInformationDAO;
import dao.UserInformationDaoJdbcImpl;

/**
 * Servlet implementation class GameOverServlet
 */
@WebServlet("/GameOverServlet")
/**
 * 游戏结束后，将用户名传输进来，在数据库中进行加分或减分操作
 * @author WXE
 *
 */
public class GameOverServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GameOverServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    @Override 
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
    	//judgement值可为0，1，2时分别代表三个玩家
		String judgement = request.getParameter("Judgement");
		//用户账号
		String account = request.getParameter("Acount");
		UserInformationDAO userAccount = new UserInformationDaoJdbcImpl();
		String flag = "1";
		//获胜
		if(flag.equals(judgement)) {
			userAccount.changeScore(account, 2);
		}else {
			userAccount.changeScore(account, -1);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
    @Override 
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
